package com.agmte.api.common.crud.tableAutoCreate;

import java.util.List;

public class TableHelper {

    public static List<TableInfo> getTableInfos() {
        return PgTableSynchronizer.tableInfos;
    }

    public static TableInfo getTable(String tableName) {
        for (TableInfo tableInfo : getTableInfos()) {
            if (tableInfo.getName().equals(tableName)) {
                return tableInfo;
            }
        }
        return null;
    }

    public static TableInfo getTable(Class<?> clazz) {
        for (TableInfo tableInfo : getTableInfos()) {
            if (tableInfo.getClazz().equals(clazz)) {
                return tableInfo;
            }
        }
        return null;
    }

    public static FieldInfo getField(Class<?> clazz, String fieldName) {
        for (TableInfo tableInfo : getTableInfos()) {
            if (tableInfo.getClazz().equals(clazz)) {
                for (FieldInfo fieldInfo : tableInfo.getFieldInfos()) {
                    if (fieldInfo.getFieldName().equals(fieldName)) {
                        return fieldInfo;
                    }
                }
            }
        }
        return null;
    }
}
